package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.EquipmentConnectionsCreateReqDTO;
import com.huaxin.device.dto.request.EquipmentConnectionsPageListReqDTO;
import com.huaxin.device.dto.request.EquipmentConnectionsUpdateReqDTO;
import com.huaxin.device.models.EquipmentConnection;
import com.huaxin.device.service.EquipmentConnectionsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "设备连接关系")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/equipmentConnections")
public class EquipmentConnectionsController {

    private final EquipmentConnectionsService service;

    @Operation(summary = "创建设备连接关系", description = "创建设备连接关系")
    @PostMapping("/create")
    public ResponseResult<EquipmentConnection> create(@RequestBody @Valid EquipmentConnectionsCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取设备连接关系", description = "根据ID获取设备连接关系")
    @GetMapping("/get")
    public ResponseResult<EquipmentConnection> get(
            @Parameter(description = "连接关系ID", example = "conn_001")
            @RequestParam(value = "id", required = true) String id) {
        EquipmentConnection entity = service.getByConnectionId(id);
        return ResponseResult.ok(entity);
    }

    @Operation(summary = "更新设备连接关系", description = "更新设备连接关系")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid EquipmentConnectionsUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除设备连接关系", description = "删除设备连接关系")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "连接关系ID", example = "conn_001")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "分页查询设备连接关系", description = "分页查询设备连接关系")
    @PostMapping("/page")
    public ResponseResult<IPage<EquipmentConnection>> pageQuery(@RequestBody @Valid EquipmentConnectionsPageListReqDTO in) {
        return service.pageQuery(in);
    }
}